package com.ruoyi.web.controller.caipiao;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.json.JSONUtil;
import com.ruoyi.caipiao.dto.req.YuReqDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.caipiao.domain.CaipiaoPl5History;
import com.ruoyi.caipiao.service.ICaipiaoPl5HistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排列5历史开奖Controller
 *
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/caipiao/historypl5")
public class CaipiaoPl5HistoryController extends BaseController {
    @Autowired
    private ICaipiaoPl5HistoryService caipiaoPl5HistoryService;

    @GetMapping("/stat1")
    public AjaxResult stat1(@RequestParam(value = "qs", required = false) Long qs) {
        String data = caipiaoPl5HistoryService.stat1(qs, 0);
        caipiaoPl5HistoryService.stat1(qs, 1);
        caipiaoPl5HistoryService.stat1(qs, 2);
        caipiaoPl5HistoryService.stat1(qs, 3);
        return success(data);
    }

    @GetMapping("/stat2")
    public AjaxResult stat2(@RequestParam(value = "qs", required = false) Long qs) {
        String data = caipiaoPl5HistoryService.stat2(qs, 0);
        caipiaoPl5HistoryService.stat2(qs, 1);
        caipiaoPl5HistoryService.stat2(qs, 2);
        caipiaoPl5HistoryService.stat2(qs, 3);
        return success(data);
    }

    @RequestMapping("/getYcKjNum")
    public AjaxResult getYcKjNum(@RequestBody YuReqDTO yuReqDTO) {
        HashMap<String, Object> data = caipiaoPl5HistoryService.getYcKjNum(yuReqDTO);
        String jsonStr = JSONUtil.toJsonStr(data);
        logger.info("预测期数:{}, 号码:{}", yuReqDTO.getQs(), jsonStr);
        return success().put("data", data);
    }

    @PostMapping("allHistory")
    public AjaxResult allHistory() {
        return success(caipiaoPl5HistoryService.allHistory());
    }

    /**
     * 查询排列5历史开奖列表
     */
    @PreAuthorize("@ss.hasPermi('caipiao:historypl5:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaipiaoPl5History caipiaoPl5History) {
        startPage();
        List<CaipiaoPl5History> list = caipiaoPl5HistoryService.selectCaipiaoPl5HistoryList(caipiaoPl5History);
        return getDataTable(list);
    }

    /**
     * 导出排列5历史开奖列表
     */
    @PreAuthorize("@ss.hasPermi('caipiao:historypl5:export')")
    @Log(title = "排列5历史开奖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaipiaoPl5History caipiaoPl5History) {
        List<CaipiaoPl5History> list = caipiaoPl5HistoryService.selectCaipiaoPl5HistoryList(caipiaoPl5History);
        ExcelUtil<CaipiaoPl5History> util = new ExcelUtil<CaipiaoPl5History>(CaipiaoPl5History.class);
        util.exportExcel(response, list, "排列5历史开奖数据");
    }

    /**
     * 获取排列5历史开奖详细信息
     */
    @PreAuthorize("@ss.hasPermi('caipiao:historypl5:query')")
    @GetMapping(value = "/{qs}")
    public AjaxResult getInfo(@PathVariable("qs") Long qs) {
        return success(caipiaoPl5HistoryService.selectCaipiaoPl5HistoryByQs(qs));
    }

    /**
     * 新增排列5历史开奖
     */
    @PreAuthorize("@ss.hasPermi('caipiao:historypl5:add')")
    @Log(title = "排列5历史开奖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaipiaoPl5History caipiaoPl5History) {
        return toAjax(caipiaoPl5HistoryService.insertCaipiaoPl5History(caipiaoPl5History));
    }

    /**
     * 修改排列5历史开奖
     */
    @PreAuthorize("@ss.hasPermi('caipiao:historypl5:edit')")
    @Log(title = "排列5历史开奖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaipiaoPl5History caipiaoPl5History) {
        return toAjax(caipiaoPl5HistoryService.updateCaipiaoPl5History(caipiaoPl5History));
    }

    /**
     * 删除排列5历史开奖
     */
    @PreAuthorize("@ss.hasPermi('caipiao:historypl5:remove')")
    @Log(title = "排列5历史开奖", businessType = BusinessType.DELETE)
    @DeleteMapping("/{qss}")
    public AjaxResult remove(@PathVariable Long[] qss) {
        return toAjax(caipiaoPl5HistoryService.deleteCaipiaoPl5HistoryByQss(qss));
    }
}
